package com.oim.function.ui.device;

import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;

/**
 * @author: XiaHui
 * @date: 2017年4月11日 上午9:11:15
 */
public class DeviceItem extends VBox {

	HBox topBox = new HBox();
	VBox infoBox = new VBox();

	
	Label nameShowLable = new Label("设备名：");
	Label nameLable = new Label();
	
	Label accountShowLable = new Label("账号：");
	Label accountLable = new Label();
	Label snShowLable = new Label("编号：");
	Label snLable = new Label();
	Label ipShowLable = new Label("IP：");
	Label ipLable = new Label();

	HBox bottomBox = new HBox();

	Button button = new Button();

	Label statusShowLable = new Label("设备状态：");
	Label statusImageLable = new Label();
	ImageView statusImageView = new ImageView();

	public DeviceItem() {
		initComponent();
		initEvent();
	}

	private void initComponent() {
		this.setMinWidth(300);
		this.setMaxWidth(300);
		//this.setMinSize(300, 70);
		//this.setMaxSize(300, 70);
		getChildren().add(topBox);
		getChildren().add(bottomBox);
		this.setStyle("-fx-background-color:rgba(222, 222, 222, 1)");
		this.setPadding(new Insets(5, 5, 5, 5));

		
		HBox nameHBox = new HBox();

		nameHBox.getChildren().add(nameShowLable);
		nameHBox.getChildren().add(nameLable);
		
		HBox accountHBox = new HBox();

		accountHBox.getChildren().add(accountShowLable);
		accountHBox.getChildren().add(accountLable);

		HBox snHBox = new HBox();

		snHBox.getChildren().add(snShowLable);
		snHBox.getChildren().add(snLable);

		HBox ipHBox = new HBox();

		ipHBox.getChildren().add(ipShowLable);
		ipHBox.getChildren().add(ipLable);

		// infoBox.setStyle(value);
		infoBox.setStyle("-fx-background-color:rgba(255, 255, 255, 1)");
		infoBox.getChildren().add(nameHBox);
		//infoBox.getChildren().add(accountHBox);
		infoBox.getChildren().add(snHBox);
		infoBox.getChildren().add(ipHBox);

		HBox.setHgrow(infoBox, Priority.ALWAYS);

		// topBox.setAlignment(Pos.CENTER_RIGHT);
		topBox.getChildren().add(infoBox);
		topBox.setPadding(new Insets(0, 5, 0, 5));

		Rectangle clip = new Rectangle();
		clip.setArcHeight(6);
		clip.setArcWidth(6);
		infoBox.setClip(clip);
		infoBox.widthProperty().addListener((Observable observable) -> {
			clip.setWidth(infoBox.getWidth());
		});
		infoBox.heightProperty().addListener((Observable observable) -> {
			clip.setHeight(infoBox.getHeight());
		});

		statusImageLable.setGraphic(statusImageView);

		HBox statusHBox = new HBox();

		statusHBox.getChildren().add(statusShowLable);
		statusHBox.getChildren().add(statusImageLable);

		button.setText("远程协助");

		HBox buttonHBox = new HBox();
		buttonHBox.setAlignment(Pos.CENTER_RIGHT);
		buttonHBox.getChildren().add(button);

		HBox.setHgrow(buttonHBox, Priority.ALWAYS);

		bottomBox.getChildren().add(statusHBox);
		bottomBox.getChildren().add(buttonHBox);

	}

	private void initEvent() {

	}

	public void setAccount(String account) {
		accountLable.setText(account);
	}

	public void setSn(String sn) {
		snLable.setText(sn);
	}

	public void setIP(String ip) {
		ipLable.setText(ip);
	}
	
	public void setStatusLabel(String status) {
		statusImageLable.setText(status);
	}
	
	public void setNameLabel(String name) {
		nameLable.setText(name);
	}

	public void setOnAction(EventHandler<ActionEvent> value) {
		button.setOnAction(value);
	}

}
